<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>cross domain</title>
</head>

<body>
    <h2>Status</h2>
    <p></p>
    <a href="http://127.0.0.1:3889/index2.html">去index2查看结果</a>
    <iframe src="http://127.0.0.1:3889/getmessage.html" frameborder="0"></iframe>
    <script>
        window.onload = function () {
            //在页面加载完成后主页面向iframe发送请求
            window.frames[0].postMessage('我是从127.0.0.1:3888域名传递来的(edge)', 'http://127.0.0.1:3889/index2.html');
        }

        // 主页面监听message事件,
        window.addEventListener('message', function (e) {
            var data = e.data;
            document.querySelector('p').innerHTML = data;
        }, false);
    </script>
</body>

</html>